import React, { useLayoutEffect } from 'react';
import { View, Text, Button, SafeAreaView, StyleSheet } from 'react-native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { useNavigation, useRoute } from '@react-navigation/native';


const MyPage = () => {
  const navigation = useNavigation();
  const route = useRoute();
  const { userId, userName } = route.params as { userId: number; userName: string };


  useLayoutEffect(() => {
    navigation.setOptions({
      title: '这个是我的页面',
    });
  }, [navigation]);
  
  return (
    <SafeAreaView style={styles.safe}>
      <View style={styles.container}>
        <Text style={styles.text}>欢迎来到 MyPage</Text>
        <Text>User ID: {userId}</Text>
        <Text>User Name: {userName}</Text>
        <Button title="返回首页" onPress={() => navigation.navigate('Settings')} />
      </View>
    </SafeAreaView>
  );
};

export default MyPage;

const styles = StyleSheet.create({
  safe: {
    flex: 1,
    backgroundColor: '#fff',
  },
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  text: {
    fontSize: 24,
    marginBottom: 20,
  },
});